<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.ico?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Tensorflow," />





  <link rel="alternate" href="/atom.xml" title="Kintoki's Blog" type="application/atom+xml" />






<meta name="description" content="今年2月15日，谷歌举办了首届TensorFlow Dev Summit，并且发布了TensorFlow 1.0 正式版。   3月18号，上海的谷歌开发者社区（GDG）组织了针对峰会的专场回顾活动。本文是我在活动上分享的一些回顾，主要介绍了在流利说，我们是如何使用TensorFlow来构建学生模型并应用在自适应系统里面的。首发于流利说技术团队公众号原文链接 一、应用背景自适应学习是什么自适应学习">
<meta name="keywords" content="Tensorflow">
<meta property="og:type" content="article">
<meta property="og:title" content="Deep knowledge tracing with Tensorflow">
<meta property="og:url" content="http://yoursite.com/2017/06/06/tensorflow-dkt/index.html">
<meta property="og:site_name" content="Kintoki&#39;s Blog">
<meta property="og:description" content="今年2月15日，谷歌举办了首届TensorFlow Dev Summit，并且发布了TensorFlow 1.0 正式版。   3月18号，上海的谷歌开发者社区（GDG）组织了针对峰会的专场回顾活动。本文是我在活动上分享的一些回顾，主要介绍了在流利说，我们是如何使用TensorFlow来构建学生模型并应用在自适应系统里面的。首发于流利说技术团队公众号原文链接 一、应用背景自适应学习是什么自适应学习">
<meta property="og:locale" content="default">
<meta property="og:image" content="http://yoursite.com/2017/06/06/tensorflow-dkt/dkt1.png">
<meta property="og:image" content="http://yoursite.com/2017/06/06/tensorflow-dkt/dkt.png">
<meta property="og:image" content="http://yoursite.com/2017/06/06/tensorflow-dkt/multigpu.png">
<meta property="og:updated_time" content="2019-11-24T11:45:51.547Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Deep knowledge tracing with Tensorflow">
<meta name="twitter:description" content="今年2月15日，谷歌举办了首届TensorFlow Dev Summit，并且发布了TensorFlow 1.0 正式版。   3月18号，上海的谷歌开发者社区（GDG）组织了针对峰会的专场回顾活动。本文是我在活动上分享的一些回顾，主要介绍了在流利说，我们是如何使用TensorFlow来构建学生模型并应用在自适应系统里面的。首发于流利说技术团队公众号原文链接 一、应用背景自适应学习是什么自适应学习">
<meta name="twitter:image" content="http://yoursite.com/2017/06/06/tensorflow-dkt/dkt1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/06/06/tensorflow-dkt/"/>





  <title>Deep knowledge tracing with Tensorflow | Kintoki's Blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Kintoki's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">我们所度过的每个平凡的日常，也许就是连续发生的奇迹</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-首页">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-关于">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      
        
        <li class="menu-item menu-item-分类">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-归档">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-留言">
          <a href="/board/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heart"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/06/06/tensorflow-dkt/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Kintoki">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Kintoki's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Deep knowledge tracing with Tensorflow</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-06-06T16:39:00+08:00">
                2017-06-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          
             <span id="/2017/06/06/tensorflow-dkt/" class="leancloud_visitors" data-flag-title="Deep knowledge tracing with Tensorflow">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">Visitors&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Words count in article&#58;</span>
                
                <span title="Words count in article">
                  3,192
                </span>
              

              

              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>今年2月15日，谷歌举办了首届TensorFlow Dev Summit，并且发布了TensorFlow 1.0 正式版。   3月18号，上海的谷歌开发者社区（GDG）组织了针对峰会的专场回顾活动。本文是我在活动上分享的一些回顾，主要介绍了在流利说，我们是如何使用TensorFlow来构建学生模型并应用在自适应系统里面的。首发于流利说技术团队公众号<a href="http://mp.weixin.qq.com/s?__biz=MzI0NjIzNDkwOA==&amp;mid=2247484035&amp;idx=1&amp;sn=85fa0decac95e359435f68c50865ac0b&amp;chksm=e94328f0de34a1e665e0d809b938efb34f0aa6034391891246fc223b7782ac3bfd6ddd588aa2&amp;mpshare=1&amp;scene=23&amp;srcid=0417ZArhaQpFomTwA9jROlaC#rd" target="_blank" rel="noopener">原文链接</a></p>
<h2 id="一、应用背景"><a href="#一、应用背景" class="headerlink" title="一、应用背景"></a>一、应用背景</h2><h3 id="自适应学习是什么"><a href="#自适应学习是什么" class="headerlink" title="自适应学习是什么"></a>自适应学习是什么</h3><p>自适应学习是现在教育科技领域谈得比较多的一个概念，它的核心问题可以用一句话概括，即<code>通过个性化的规划学习路径，提高学生的学习效率</code>。为什么需要自适应学习？在传统的教学过程中，每个学生的学习路径是一致的，由于学生个人基础和学习能力的差异性，这种千人一面的做法对大部分学生来说这种方式其实比较低效。由此我们很自然的可以想到：如果我们能够<strong>根据学生的能力，去匹配合适的教学内容</strong>，就应该可以提高他们的学习效率。而这正是自适应系统希望达成的目标。</p>
<a id="more"></a>
<h3 id="学生模型"><a href="#学生模型" class="headerlink" title="学生模型"></a>学生模型</h3><p>那么自适应学习是如何达成这个目标的呢？这包含了两个核心问题，首先是<strong>学生的能力的评估</strong>，正确的评估学生的能力是后续一切工作的基础，这是学生模型关心的问题。 其次是在评估好学生的能力后，<strong>如何推送合适的内容</strong>，这是教学模型所关心的问题。本篇文章我们来讲讲如何利用TensorFlow来构建学生模型。</p>
<p>为了选择一个合适的学生模型，首先需要了解学生学习的过程。一个典型的学习过程是一个时间序列，用户在这个时间序列的各个时刻进行了一些学习行为，从而提高了自身的能力。我们可以假设学生的能力是可以通过学生在各个时刻回答问题的对错来反映的。要注意的是，由于学生学习时间的跨度可能很大，不能认为学生的水平保持不变，所以直接使用一些评测的方法（做了学生能力不变的假设）是不合适的。</p>
<h3 id="Deep-Knowledge-Tracing"><a href="#Deep-Knowledge-Tracing" class="headerlink" title="Deep Knowledge Tracing"></a>Deep Knowledge Tracing</h3><p>为了对学习序列建模，并评估学生各个时刻的能力，我们采用了Deep Knowledge Tracing（DKT）模型，这个模型是由Stanford大学的Piech Chris等人在NIPS 2015发表的，其本质是一个Seq2Seq的RNN模型，我们来看下模型的结构图：</p>
<p><img src="dkt1.png" alt=""></p>
<p>上图是DKT模型按照时间展开的示意图，其输入序列$x_1, x_2, x_3 …$对应了$t_1, t_2, t_3 …$时刻学生答题信息的编码，隐层状态对应了各个时刻学生的知识点掌握情况，模型的输出序列对应了各时刻学生回答题库中的所有习题答对的概率。</p>
<p><img src="dkt.png" alt=""></p>
<p>现在以上图为例来看看模型的各层结构。简单起见，假设题库总共有4道习题，那么首先可以确定的输出层的节点数量为4，对应了各题回答正确的概率。接着，如果我们对输出采用one-hot编码，输入层的节点数就是<code>题目数量 * 答题结果 = 4 * 2 = 8</code>个。首先将输入层全连接到RNN的隐层，接着建立隐层到输出层的全连接，最后使用Sigmoid函数作为激活函数，一个基础的DKT模型就构建完毕了。接着为了训练模型，定义如下的损失函数:</p>
<p>$$ \tag{1} L = \sum_{t}\ell(y^{T}\delta(q_{t+1}), a_{t+1})$$</p>
<p>其中$y$是$t$时刻的模型预测输出，$q_{t+1}$是$t+1$时刻用户回答的题目ID（one-hot向量），$a_{t+1}$是$t+1$时刻的用户答题的对错, $\ell$是<code>binary cross entropy</code>损失函数。下面我们用几十行TensorFlow代码来实现一下这个模型。</p>
<h2 id="二、模型构建"><a href="#二、模型构建" class="headerlink" title="二、模型构建"></a>二、模型构建</h2><p>首先初始化模型参数，并且用<code>tf.placeholder</code>来接收模型的输入：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># encoding:utf-8</span></span><br><span class="line"><span class="keyword">import</span> tensorflow <span class="keyword">as</span> tf</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">TensorFlowDKT</span><span class="params">(object)</span>:</span></span><br><span class="line">  <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self, config)</span>:</span></span><br><span class="line">    self.hidden_neurons = hidden_neurons = config[<span class="string">"hidden_neurons"</span>]</span><br><span class="line">    self.num_skills = num_skills = config[<span class="string">"num_skills"</span>]  <span class="comment"># 题库的题目数量</span></span><br><span class="line">    self.input_size = input_size = config[<span class="string">"input_size"</span>]  <span class="comment"># 输入层节点数，等于题库数量 * 2</span></span><br><span class="line">    self.batch_size = batch_size = config[<span class="string">"batch_size"</span>]</span><br><span class="line">    self.keep_prob_value = config[<span class="string">"keep_prob"</span>]</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 接收输入</span></span><br><span class="line">    self.input_data = tf.placeholder(tf.float32, [batch_size, <span class="keyword">None</span>, input_size])  <span class="comment"># 答题信息</span></span><br><span class="line">    self.sequence_len = tf.placeholder(tf.int32, [batch_size])  <span class="comment"># 一个batch中每个序列的有效长度</span></span><br><span class="line">    self.max_steps = tf.placeholder(tf.int32)  <span class="comment"># max seq length of current batch.</span></span><br><span class="line">    self.keep_prob = tf.placeholder(tf.float32)  <span class="comment"># dropout keep prob</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 接收标签信息</span></span><br><span class="line">    self.target_id = tf.placeholder(tf.int32, [batch_size, <span class="keyword">None</span>]) <span class="comment"># 回答的题目ID</span></span><br><span class="line">    self.target_correctness = tf.placeholder(tf.float32, [batch_size, <span class="keyword">None</span>]) <span class="comment"># 答题对错情况</span></span><br></pre></td></tr></table></figure>
<p>接着构建RNN层：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># create rnn cell</span></span><br><span class="line">hidden_layers = []</span><br><span class="line"><span class="keyword">for</span> idx, hidden_size <span class="keyword">in</span> enumerate(hidden_neurons):</span><br><span class="line">  lstm_layer = tf.contrib.rnn.BasicLSTMCell(num_units=hidden_size, state_is_tuple=<span class="keyword">True</span>)</span><br><span class="line">  hidden_layer = tf.contrib.rnn.DropoutWrapper(cell=lstm_layer,output_keep_prob=self.keep_prob)</span><br><span class="line">  hidden_layers.append(hidden_layer)</span><br><span class="line">  self.hidden_cell = tf.contrib.rnn.MultiRNNCell(cells=hidden_layers, state_is_tuple=<span class="keyword">True</span>)</span><br><span class="line">        </span><br><span class="line">  <span class="comment"># dynamic rnn</span></span><br><span class="line">  state_series, self.current_state = tf.nn.dynamic_rnn(cell=self.hidden_cell, inputs=self.input_data, sequence_length=self.sequence_len,dtype=tf.float32)</span><br></pre></td></tr></table></figure>
<p>这里我们用<code>tf.dynamic_rnn</code>构建了一个多层循环神经网络，<code>cell</code>参数用来指定了隐层神经元的结构，<code>sequence_len</code>参数表示一个batch中各个序列的有效长度。<code>state_series</code>表示隐层的输出，是一个三阶的Tensor，<code>self.current_state</code>表示batch各个序列的最后一个step的隐状态。</p>
<p>输出层：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># output layer</span></span><br><span class="line">output_w = tf.get_variable(<span class="string">"W"</span>, [hidden_neurons[<span class="number">-1</span>], num_skills])</span><br><span class="line">output_b = tf.get_variable(<span class="string">"b"</span>, [num_skills])</span><br><span class="line">self.state_series = tf.reshape(state_series, [batch_size*self.max_steps, hidden_neurons[<span class="number">-1</span>]])</span><br><span class="line">self.logits = tf.matmul(self.state_series, output_w) + output_b</span><br><span class="line">self.mat_logits = tf.reshape(self.logits, [batch_size, self.max_steps, num_skills])</span><br><span class="line">self.pred_all = tf.sigmoid(self.mat_logits)  <span class="comment"># predict 输出</span></span><br></pre></td></tr></table></figure>
<p>输出层我们构建了两个变量作为隐层到输出层的连接的参数，并用<code>tf.sigmoid</code>作为激活函数。到这里我们已经可以得到模型的预测输出<code>self.pred_all</code>，这也是一个三阶的张量，<code>shape</code>为<code>(batch_size, self.max_steps, num_skills)</code>。</p>
<p>为了训练模型，还需要计算模型损失函数和梯度，我们结合预测和标签信息来获得损失函数：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># compute loss</span></span><br><span class="line">flat_logits = tf.reshape(self.logits, [<span class="number">-1</span>])</span><br><span class="line">flat_target_correctness = tf.reshape(self.target_correctness, [<span class="number">-1</span>])</span><br><span class="line">flat_base_target_index = tf.range(batch_size * self.max_steps) * num_skills</span><br><span class="line">flat_bias_target_id = tf.reshape(self.target_id, [<span class="number">-1</span>])</span><br><span class="line">flat_target_id = flat_bias_target_id + flat_base_target_index</span><br><span class="line">flat_target_logits = tf.gather(flat_logits, flat_target_id)</span><br><span class="line">self.pred = tf.sigmoid(tf.reshape(flat_target_logits, [batch_size, self.max_steps]))</span><br><span class="line">self.binary_pred = tf.cast(tf.greater_equal(self.pred, <span class="number">0.5</span>), tf.int32)</span><br><span class="line">loss = tf.nn.sigmoid_cross_entropy_with_logits(labels=flat_target_correctness, logits=flat_target_logits)</span><br><span class="line">self.loss = tf.reduce_sum(loss)</span><br></pre></td></tr></table></figure>
<p>获得梯度并更新参数：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">self.lr = tf.Variable(<span class="number">0.0</span>, trainable=<span class="keyword">False</span>)</span><br><span class="line">trainable_vars = tf.trainable_variables()</span><br><span class="line">self.grads, _ = tf.clip_by_global_norm(tf.gradients(self.loss, trainable_vars), <span class="number">4</span>)</span><br><span class="line">optimizer = tf.train.GradientDescentOptimizer(self.lr)</span><br><span class="line">self.train_op = optimizer.apply_gradients(zip(self.grads, trainable_vars))</span><br></pre></td></tr></table></figure>
<p>需要注意的是，在用<code>tf.gradients</code>得到梯度后，我们使用了<code>tf.clip_by_global_norm</code>方法，这主要是为了防止梯度爆炸的现象。最后应用了一次梯度下降得到的<code>self.train_op</code>就是计算图的训练结点。得到训练结点后，我们的计算图(Graph)就已经构造完毕，接着只需要创建一个<code>tf.Session</code>对象，并调用其<code>run()</code>方法来运行计算图就可以进行模型训练和测试了。由于训练和测试的接收的<code>feed_dict</code>类似，我们定义<code>step</code>方法来用作训练和测试，如下：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">step</span><span class="params">(self, sess, input_x, target_id, target_correctness, sequence_len, is_train)</span>:</span></span><br><span class="line">  _, max_steps, _ = input_x.shape</span><br><span class="line">  input_feed = &#123;self.input_data: input_x,</span><br><span class="line">                self.target_id: target_id,</span><br><span class="line">                self.target_correctness: target_correctness,</span><br><span class="line">                self.max_steps: max_steps,</span><br><span class="line">                self.sequence_len: sequence_len&#125;</span><br><span class="line">  <span class="keyword">if</span> is_train:</span><br><span class="line">    input_feed[self.keep_prob] = self.keep_prob_value</span><br><span class="line">    train_loss, _, _ = sess.run([self.loss, self.train_op, self.current_state], input_feed)</span><br><span class="line">    <span class="keyword">return</span> train_loss</span><br><span class="line">  <span class="keyword">else</span>:</span><br><span class="line">    input_feed[self.keep_prob] = <span class="number">1</span></span><br><span class="line">    bin_pred, pred, pred_all = sess.run([self.binary_pred, self.pred, self.pred_all], input_feed)</span><br><span class="line">    <span class="keyword">return</span> bin_pred, pred, pred_all</span><br></pre></td></tr></table></figure>
<p>定义<code>assign_lr</code>方法来设置学习率:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">assign_lr</span><span class="params">(self, session, lr_value)</span>:</span></span><br><span class="line">session.run(tf.assign(self.lr, lr_value))</span><br></pre></td></tr></table></figure>
<p>至此，<code>TensorFlowDKT</code>类就构造完毕了，我们可以这样使用它：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># process data ...</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># config and create model</span></span><br><span class="line"><span class="comment"># config = ...</span></span><br><span class="line">model = TensorFlowDKT(config)</span><br><span class="line"></span><br><span class="line"><span class="comment"># create session and init all variables</span></span><br><span class="line">sess = tf.Session()</span><br><span class="line">sess.run(tf.global_variables_initializer())</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> range(num_epoch):</span><br><span class="line">  <span class="comment"># train</span></span><br><span class="line">  <span class="comment"># lr_value = ...</span></span><br><span class="line">  model.assign_lr(sess, lr_value)  <span class="comment"># assign learning rate</span></span><br><span class="line">  train_generator.shuffle()  <span class="comment"># random shuffle before each epoch</span></span><br><span class="line">  <span class="keyword">while</span> <span class="keyword">not</span> train_generator.end:</span><br><span class="line">    input_x, target_id, target_correctness, seqs_len, _ = train_generator.next_batch()</span><br><span class="line">    overall_loss += model.step(sess, input_x, target_id, target_correctness, seqs_len, is_train=<span class="keyword">True</span>)</span><br><span class="line">  <span class="comment"># test</span></span><br><span class="line">  <span class="keyword">while</span> <span class="keyword">not</span> test_generator.end:</span><br><span class="line">    input_x, target_id, target_correctness, seqs_len, _ = test_generator.next_batch()</span><br><span class="line">    binary_pred, pred, _ = model.step(sess, input_x, target_id, target_correctness, seqs_len, is_train=<span class="keyword">False</span>)</span><br><span class="line">  <span class="comment"># calculate metrics ...</span></span><br></pre></td></tr></table></figure>
<p>Demo的完整代码，见<a href="https://github.com/lingochamp/tensorflow-dkt" target="_blank" rel="noopener">https://github.com/lingochamp/tensorflow-dkt</a></p>
<h2 id="三、工程实践"><a href="#三、工程实践" class="headerlink" title="三、工程实践"></a>三、工程实践</h2><p>流利说的<strong>懂你英语</strong>课程，到16年12月份为止，已经积累了数亿量级用户答题数据，在处理这些数据优化模型指标的过程中，我们也积累了一些实践经验。</p>
<h2 id="Truncated-BPTT"><a href="#Truncated-BPTT" class="headerlink" title="Truncated BPTT"></a>Truncated BPTT</h2><p>我们收集到的学习数据里，最长的序列长度超过五万。出于计算效率的考虑，包括TensorFlow在内的多数深度框架在进行BPTT的时候都会将序列按照时间维度展开，这在序列长度达到五万的情况下是不现实的（显存会爆）。所以我们需要将长的序列切断分为多个序列，然后保存前一部分序列训练的隐状态作为接下来一部分序列的初始状态输入，这样来进行长序列的训练。</p>
<h3 id="多GPU加速"><a href="#多GPU加速" class="headerlink" title="多GPU加速"></a>多GPU加速</h3><p>当数据到达数亿的量级以后，进行一次训练已经需要比较多的时间了，这个时候我们可以通过多GPU并行来加速训练。这里我们使用Multi Tower结构，这是一种数据并行的多GPU方案，我们来看下它的示意图：</p>
<p><img src="multigpu.png" alt=""></p>
<p>可以看到在Multi Tower结构里，每个GPU持有一个模型实例，这些实例之间共享参数的。训练开始后，每次我们将多个batch数据分别喂给各个模型实例，在各GPU设备分别求得梯度信息。 接着，我们将收集到的梯度返回到CPU，取平均以后，用来更新模型的参数。 由于模型的参数是共享的，这也就意味着所有模型实例的参数都得到了更新。接着我们来看下，以<code>TensorFlowDKT</code>类为例，我们如何用Multi Tower结构来构造训练结点：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">multi_gpu_model</span><span class="params">(num_gpus=<span class="number">1</span>, model_config=None)</span>:</span></span><br><span class="line">  tower_grads = []</span><br><span class="line">  <span class="keyword">for</span> i <span class="keyword">in</span> range(num_gpus):</span><br><span class="line">    <span class="keyword">with</span> tf.device(<span class="string">"/gpu:%d"</span> % i):</span><br><span class="line">      <span class="keyword">with</span> tf.name_scope(<span class="string">"tower_%d"</span> % i):  <span class="comment"># 用name_scope区分各模型</span></span><br><span class="line">        model = TensorFlowDKT(model_config)  <span class="comment"># 为每个GPU构造一个模型实例</span></span><br><span class="line">        tf.add_to_collection(<span class="string">"train_model"</span>, model)  <span class="comment"># add_to_collection，方便feed数据</span></span><br><span class="line">        tower_grads.append(model.grads)  <span class="comment"># 收集梯度信息</span></span><br><span class="line">        tf.add_to_collection(<span class="string">"loss"</span>, model.loss)</span><br><span class="line">    tf.get_variable_scope().reuse_variables()  <span class="comment"># 重用同一作用域内的变量</span></span><br><span class="line">  </span><br><span class="line">  <span class="keyword">with</span> tf.device(<span class="string">"cpu:0"</span>):</span><br><span class="line">    averaged_gradients = average_gradients(tower_grads)  <span class="comment"># 对返回的梯度取平均</span></span><br><span class="line">    opt = tf.train.GradientDescentOptimizer(<span class="number">0.5</span>)</span><br><span class="line">    train_op = opt.apply_gradients(zip(averaged_gradients, tf.trainable_variables()))</span><br><span class="line">  <span class="keyword">return</span> train_op</span><br></pre></td></tr></table></figure>
<p>其中<code>average_gradients</code>方法的代码可以参考<a href="https://github.com/tensorflow/models/blob/master/tutorials/image/cifar10/cifar10_multi_gpu_train.py" target="_blank" rel="noopener">https://github.com/tensorflow/models/blob/master/tutorials/image/cifar10/cifar10_multi_gpu_train.py</a> 。接着我们构造一个方法来返回<code>feed_dict</code>：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">generate_feed_dict</span><span class="params">(data_generator)</span>:</span></span><br><span class="line">  feed_dict = &#123;&#125;</span><br><span class="line">  models = tf.get_collection(<span class="string">"train_model"</span>)  <span class="comment"># get_collection，取回模型</span></span><br><span class="line">  <span class="keyword">for</span> model <span class="keyword">in</span> models:</span><br><span class="line">    inputs, target_id, target_correctness, seqs_len, max_len = data_generator.next_batch()</span><br><span class="line">    feed_dict[model.input_data] = inputs</span><br><span class="line">    feed_dict[model.target_id] = target_id</span><br><span class="line">    feed_dict[model.target_correctness] = target_correctness</span><br><span class="line">    feed_dict[model.max_steps] = max_len</span><br><span class="line">    feed_dict[model.sequence_len] = seqs_len</span><br><span class="line">    feed_dict[model.keep_prob] = model.keep_prob_value</span><br><span class="line">  <span class="keyword">return</span> feed_dict</span><br></pre></td></tr></table></figure>
<p>最后由于<code>dynamic_rnn</code>的一些<code>Operation</code>尚不支持GPU，在训练开始前，我们需要配置一下<code>Session</code>避免出错：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=<span class="keyword">True</span>))</span><br></pre></td></tr></table></figure>
<p>完成上面的步骤，我们就可以用多GPU来加速模型训练了。</p>
<h3 id="模型导出"><a href="#模型导出" class="headerlink" title="模型导出"></a>模型导出</h3><p>在流利说，学生模型训练是用Python API完成的，而学生模型预测服务则是用C++实现的。关于如何从C++如何从Protobuf文件中加载Graph可以参考<a href="https://www.tensorflow.org/tutorials/image_recognition。这里有一个模型导出的问题，即Python" target="_blank" rel="noopener">https://www.tensorflow.org/tutorials/image_recognition。这里有一个模型导出的问题，即Python</a> 中的<code>tf.train.write_graph</code>方法只能够保存模型的图结构，而不能保存变量的值到Protobuf文件中。这个问题可以通过将Variables转换为<code>tf.constant</code>来解决， <code>tensorflow.python.tools.freeze_graph</code>提供了这样的方法。</p>
<h2 id="结语"><a href="#结语" class="headerlink" title="结语"></a>结语</h2><p>TensorFlow是一个十分简单易用的机器学习框架，也是目前最流行的深度学习框架，它可以让机器学习研究者更少的关注底层的问题，而专注于问题的解决和算法的优化上。流利说算法团队从16年初开始就将TensorFlow应用到内部的机器学习项目里面，积累了很多相关的使用经验，从而帮助我们的用更智能算法来服务用户。</p>
<h3 id="References"><a href="#References" class="headerlink" title="References"></a>References</h3><ol>
<li>Piech, Chris, et al. “Deep knowledge tracing.” <em>Advances in Neural Information Processing Systems</em>. 2015.</li>
<li><a href="https://www.tensorflow.org/" target="_blank" rel="noopener">https://www.tensorflow.org/</a></li>
<li><a href="https://github.com/tensorflow/tensorflow" target="_blank" rel="noopener">https://github.com/tensorflow/tensorflow</a></li>
</ol>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Tensorflow/" rel="tag"><i class="fa fa-tag"></i>Tensorflow</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/11/24/RL5-TD-learning/" rel="prev" title="强化学习（五）时间差分学习">
                强化学习（五）时间差分学习 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.jpg"
                alt="Kintoki" />
            
              <p class="site-author-name" itemprop="name">Kintoki</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">4</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">2</span>
                  <span class="site-state-item-name">tags</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/jinxulin" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:jinxulin@163.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://weibo.com/jinxulin/home" target="_blank" title="微博">
                      
                        <i class="fa fa-fw fa-twitter"></i>微博</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://www.cnblogs.com/jinxulin" target="_blank" title="博客园">
                      
                        <i class="fa fa-fw fa-github"></i>博客园</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、应用背景"><span class="nav-number">1.</span> <span class="nav-text">一、应用背景</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#自适应学习是什么"><span class="nav-number">1.1.</span> <span class="nav-text">自适应学习是什么</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#学生模型"><span class="nav-number">1.2.</span> <span class="nav-text">学生模型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Deep-Knowledge-Tracing"><span class="nav-number">1.3.</span> <span class="nav-text">Deep Knowledge Tracing</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、模型构建"><span class="nav-number">2.</span> <span class="nav-text">二、模型构建</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、工程实践"><span class="nav-number">3.</span> <span class="nav-text">三、工程实践</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Truncated-BPTT"><span class="nav-number">4.</span> <span class="nav-text">Truncated BPTT</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#多GPU加速"><span class="nav-number">4.1.</span> <span class="nav-text">多GPU加速</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#模型导出"><span class="nav-number">4.2.</span> <span class="nav-text">模型导出</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#结语"><span class="nav-number">5.</span> <span class="nav-text">结语</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#References"><span class="nav-number">5.1.</span> <span class="nav-text">References</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Kintoki</span>

  
</div>


  <div class="powered-by">  Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>


<div class="theme-info">
  Hosted by <a href="https://pages.coding.me" style="font-weight: bold">Coding Pages</a>
</div>
        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>  
    <span class="site-pv">
      <i class="fa fa-user"></i> 访问人数
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
    <span class="site-pv">
      <i class="fa fa-eye"></i> 总访问量
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
</div>

        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("WEB822paP0cwBpoIerKOWcF4-gzGzoHsz", "mxnf4Poo55CyjlisDHiMELxR");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  

</body>
</html>
